package com.platform.modules.sys.service.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.sys.dao.SysDictGroupDao;
import com.platform.modules.sys.entity.SysDictGroupEntity;
import com.platform.modules.sys.service.SysDictGroupService;

/**
 * 数据字典分组Service实现类
 *
 * @author 肖亮
 */
@Service("sysDictGroupService")
public class SysDictGroupServiceImpl extends ServiceImpl<SysDictGroupDao, SysDictGroupEntity>
		implements SysDictGroupService {

	@Override
	public List<SysDictGroupEntity> queryAll(Map<String, Object> params) {
		return baseMapper.queryAll(params);
	}

	@Override
	public Page queryPage(Map<String, Object> params) {
		// 排序
		params.put("sidx", "T.CREATE_TIME");
		params.put("asc", false);
		Page<SysDictGroupEntity> page = new Query<SysDictGroupEntity>(params).getPage();
		return page.setRecords(baseMapper.selectSysDictGroupPage(page, params));
	}

	@Override
	public void add(SysDictGroupEntity sysDictGroup) {
		sysDictGroup.setCreateTime(new Date());
		this.save(sysDictGroup);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void update(SysDictGroupEntity sysDictGroup) {
		this.updateById(sysDictGroup);
	}

	@Override
	public void delete(String id) {
		this.removeById(id);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteBatch(String[] ids) {
		this.removeByIds(Arrays.asList(ids));
	}
}
